package com.adtech.farmProducts.adapter;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.TextView;

import com.adtech.common.widgets.recycler.RecyclerViewAdapter;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.model.BillingType;
import com.adtech.farmProducts.model.Reason;

/**
 * Author:  xiaocz.
 * Date:    2019/05.04.
 * Descr:  支付方式
 */
public class PayTypeAdapter extends RecyclerViewAdapter<Reason> {

    public PayTypeAdapter(AdapterListener<Reason> adapterListener) {
        super(adapterListener);
    }

    @Override
    protected int getItemViewType(int position, Reason data) {
        return R.layout.item_pay_redio;
    }

    @Override
    protected ViewHolder<Reason> getViewHolder(View view, int viewType) {
        return new CouponsViewHolder(view);
    }

    private static class CouponsViewHolder extends ViewHolder<Reason> {

        private int[] payType={R.drawable.btn_weixin,R.drawable.btn_weix,R.drawable.btn_weixin};
        private TextView rbBilling;

        /**
         * 构造方法
         *
         * @param itemView
         */
        public CouponsViewHolder(View itemView) {
            super(itemView);
            rbBilling = itemView.findViewById(R.id.rb_billing);
        }

        @Override
        protected void onBind(final Reason data, final int position) {
            rbBilling.setText(data.getContent());
            Drawable rightDrawable,payTypeDrawable;
            if (data.isSelected()) {
                rightDrawable = mContext.getResources().getDrawable(R.drawable.ic_payment_checked);
            } else {
                rightDrawable = mContext.getResources().getDrawable(R.drawable.ic_payment_unchecked);
            }
            payTypeDrawable=mContext.getResources().getDrawable(payType[position]);
            rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());
            payTypeDrawable.setBounds(0, 0, payTypeDrawable.getMinimumWidth()/2, payTypeDrawable.getMinimumHeight()/2);
            rbBilling.setCompoundDrawables(payTypeDrawable, null, rightDrawable,null);
        }

        @Override
        public boolean isNeedClick() {
            return true;
        }
    }

    public interface onClickListener {
        void onClickButton(int value, int position, BillingType data);
    }
}